
import 'dart:io';

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/services.dart';
import 'package:flutter_ahj_app/base/basewidget/HttpUtils/HttpBaseConst.dart';
import 'package:flutter_ahj_app/base/cunchu/UserInfoUtils.dart';
import 'package:flutter_ahj_app/base/utils/ToastUtils.dart';

const MethodChannel _kChannel = MethodChannel('com.ahj/livePlayPlugin');
//const MethodChannel _kChannel1 = MethodChannel('com.ahj/messagelivePlayPlugin');
class WXZhiBoUtils{
  /**
   * 打开直播
   * name 直播名称
   * url 直播地址
   * desc 描述
   * zhiboID 直播ID
   * userPhoto 用户头像
   * type 直播类型
   * number 直播人数
   * userName用户姓名
   * zhuJiangPerson主讲人
   * speaker直播人
   * videoType 1 = 正在直播, 2 = 直播回放
   * baseUrl 生产环境 测试环境
   * ownNickName 当前登录用户的昵称 
   */
  static Future<String>  openZhibo(String name,String url,String desc,String zhiboID,String userPhoto,String type,String number ,String userName , String speaker,String zhuJiangPerson, String videoType) async {
    Map<String, dynamic> map = Map();
    map["name"] = name;
    map["url"] = url;
    map["desc"] = desc;
    map["zhiboID"] = zhiboID;
    map["userPhoto"] = userPhoto;
    map["type"] = type;
    map["number"] = number;
    map["userName"] = userName;
    map["speaker"] = speaker;
    map["userToken"] = zhuJiangPerson;
    map["videoType"] = videoType;
    map["baseUrl"] = HttpBaseConst.serverUrl;
    map["ownNickName"] = UserInfoUtils.getUserNiceName();
    try {
      var result = await(new Connectivity().checkConnectivity());
      if (result==ConnectivityResult.none) {
        ToastUtils.showToast("网络连接失败");
      }else{
        return  await _kChannel.invokeMethod('livePlay', map);
      }
    } on SocketException catch (_) {

    }



  }


}